import {
  checkLogin
} from './auth.js'
new Vue({
  el: '#app',
  data: {
    username: '',
    password: '',
    password2: ''
  },
  async created() {
    this.IS_LOGIN = await checkLogin()
    if (this.IS_LOGIN) {
      location.href = '/'
    }
  },
  methods: {
    async register() {
      if (this.username == '' || this.password == '' || this.password2 == '') {
        this.$message.error('请填写完整信息');
        return;
      }
      if (this.password !== this.password2) {
        this.$message.error('密码不一致');
        return;
      }
      console.log('register执行了');
      const res = await request.post('/user/register', {
        username: this.username,
        password: this.password,
        password2: this.password2
      })
      console.log(res);
      if (res.code == 200) {
        console.log('注册成功');
        this.$message.success('注册成功,正在调转登录...');
        setTimeout(() => {
          window.location.href = '/web/login.html';
        }, 2000);
      } else {
        this.$message.error(res.msg);
      }
    }
  }
})